package org.imaginedays.androidall.http;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.imaginedays.androidall.constants.Constants;
import org.imaginedays.androidall.error.AndroidAllError;
import org.imaginedays.androidall.error.AndroidAllException;
import org.imaginedays.androidall.error.AndroidAllParseException;
import org.imaginedays.androidall.types.BaseType;
import org.imaginedays.androidall.types.UploadFile;
import org.imaginedays.androidall.xml.parsers.Parser;

public interface HttpApi {

	public static final boolean DEBUG = Constants.DEBUG;

	abstract public BaseType doHttpRequest(HttpRequestBase httpRequest,
			Parser<? extends BaseType> parser) throws AndroidAllParseException,
			AndroidAllException, IOException;

	abstract public String doHttpPost(String url,
			NameValuePair... nameValuePairs) throws AndroidAllParseException,
			AndroidAllException, IOException;

	/**
	 * HttpPost 上传图片与参数
	 */
	abstract public BaseType httpPostWithImg(String url,String imagePath,
			HashMap<String, String> params,Parser<? extends BaseType> parser) throws Exception;

	abstract public HttpGet createHttpGet(String url,
			NameValuePair... nameValuePairs);

	abstract public HttpPost createHttpPost(String url,
			NameValuePair... nameValuePairs);

	abstract public HttpURLConnection createHttpURLConnectionPost(URL url,
			String boundary) throws IOException;

	/**
	 * 普通的 HttpURLConnection GET请求
	 */
	abstract public BaseType accessServerByGet(String serverUrl,
			HashMap<String, String> params, Parser<? extends BaseType> parser);

	/**
	 * 带图片与参数的 HttpURLConnection GET请求
	 */
	abstract public BaseType accessServerByGetWithImg(String urlPath,
			Map<String, String> params, UploadFile file,
			Parser<? extends BaseType> parser) throws Exception;

	/**
	 * 普通参数的 HttpURLConnection POST
	 * 
	 * @param url
	 * @param params
	 * @param parser
	 * @return
	 * @throws Exception
	 */
	abstract public BaseType accessServerByPost(String url,
			Map<String, String> params, Parser<? extends BaseType> parser)
			throws AndroidAllError, AndroidAllParseException;

	/**
	 * 带图片与参数的 HttpURLConnection POST
	 * 
	 * @param url
	 * @param imagePath
	 * @param params
	 * @param parser
	 * @return
	 * @throws Exception
	 */
	abstract public BaseType accessServerByPostWithImg(String url,
			String imagePath, Map<String, String> params,
			Parser<? extends BaseType> parser) throws AndroidAllError,
			AndroidAllParseException;

}
